 {block name="body"}
<link rel="shortcut icon" href="favicon.ico">
<link href="__CSS__/bootstrap.min.css" rel="stylesheet">
<link href="__CSS__/font-awesome.min.css" rel="stylesheet">
<link href="__CSS__/animate.min.css" rel="stylesheet">
<link href="__CSS__/style.min.css" rel="stylesheet">
<link href="__CSS__/admin.css" rel="stylesheet">
<div class="ibox float-e-margins">
	<div class="ibox-content">
		<form method="post" action="{:url('goods_list')}">
			<div class="form-group" style="padding-left: 20px;">
				商品编码 <input type="text" id="goods_no" name="goods_no" value="" placeholder="请输入商品编码" class="bank" />
				商品名称 <input type="text" id="goods_name" name="goods_name" value="" placeholder="请输入商品名称" class="bank" />
				<span class="bank"><button type="submit" class="btn btn-sm btn-primary"><li class="fa fa-search"> 查询</li></button> </span>
			</div>
		</form>
		<div class="hr-line-dashed"></div>
		<div class="example-wrap">
			<div class="example">				
					<table class="table table-bordered table-hover">
						<thead>
							<tr class="long-th">
								<th width="50">
									<input type="checkbox" name="check" id="check" class="check-all">
								</th>
								<th>商品名称</th>
								<th>单位</th>
								<th>店铺零售价(元)</th>
								<th>状态</th>
							</tr>
						</thead>
						<tbody>
							{foreach name="list" item="ad"}
							<tr>
								<td class="text-center">
									<input type="checkbox" name="ids[]" value="{$ad.id}" data-no="{$ad.goods_no}" 
										data-name="{$ad.goods_name}" data-price="{$ad.sale_price}"  data-id="{$ad.id}"
										data-unit="{$ad.unit}" >
								</td>
								<td class="text-center">{$ad.goods_name}</td>
								<td class="text-center">{$ad.unit}</td>
								<td class="text-center">{$ad.sale_price}</td>
								<td class="text-center">
									{if $ad.goods_state == 2}
									在售
									{else}
									停售
									{/if}
								</td>
							</tr>
							{/foreach}
						</tbody>
					</table>
					
                   	<div class="form-group">
						<div class="col-sm-4 col-sm-offset-10">							
							<button class="btn btn-info"><i class="fa fa-save"></i> 保存</button>&nbsp;&nbsp;
							<span onclick="wclose()"><a class="btn btn-danger"><i class="fa fa-arrow-left"></i> 返回 </a></span>
						</div>
					</div>
			</div>
		</div>
	</div>
</div>
{/block} {block name="script"}
<script src="__JS__/jquery.min.js"></script>
<script src="__JS__/bootstrap.min.js"></script>
<script src="__JS__/jquery.metisMenu.js"></script>
<script src="__JS__/jquery.slimscroll.min.js"></script>
<script src="__LIB__/layer/layer.js"></script>
<script src="__JS__/core.min.js"></script>
<script src="__JS__/pace.min.js"></script>
<script src="__JS__/jquery.form.js"></script>
<script src="__LIB__/datepicker/WdatePicker.js"></script>
<script src="__LIB__/validate/jquery.validate.min.js"></script>
<script src="__LIB__/validate/messages_zh.min.js"></script>
<script src="__LIB__/validate/add_validate.min.js"></script>
<script src="__LIB__/fileinput/js/fileinput.min.js"></script>
<script src="__LIB__/fileinput/js/locales/zh.js"></script>
<script src="__LIB__/ueditor/ueditor.config.js" type="text/javascript"></script>
<script src="__LIB__/ueditor/ueditor.all.js" type="text/javascript"></script>
<script>
	function wclose(){
    	var index = parent.layer.getFrameIndex(window.name); //获取窗口索引  
        parent.layer.close(index);  
	}
</script>
<script>
	$("#check").click(function(){
        if(this.checked){
            $("input[name='ids[]']").each(function(){this.checked=true})
        }else{
            $("input[name='ids[]']").each(function(){this.checked=false})
        }
    });
    
    $(".btn-info").click(function(){
		var id_array = new Array(); 
		var name = new Array(); 
		var id = new Array(); 
		var price = new Array(); 
		var no = new Array(); 
		var unit = new Array(); 
		var hasChk = $('input[name="ids[]"]:checked').is(':checked');
		if(!hasChk){
			layer.msg("请选择商品!");
			return false;
		}
		$('input[name="ids[]"]:checked').each(function(){ 
		    id_array.push($(this).val());//向数组中添加元素  
			name.push($(this).attr("data-name"));
			id.push($(this).attr("data-id"));
			price.push($(this).attr("data-price"));
			no.push($(this).attr("data-no"));
			unit.push($(this).attr("data-unit"));
		}); 
		
		var html="";
		for(var i=0;i<id_array.length;i++){
			var has_goods=$("#goodsid{$type}"+id_array,parent.document);
			if(has_goods.length==0){
				var tr='<tr>'+
				'<input type="hidden" name="goodsid{$type}[]" id="goodsid'+id_array[i]+'" value='+id_array[i]+' />'+
				'<input type="hidden" name="goods_names{$type}[]"  value='+name[i]+' />'+
	        	'<td>'+name[i]+'</td>'+
	        	'<td><input type="text"  name="num{$type}[]" value="1"/></td>'+
	        	'<td>'+price[i]+'</td>'+
	        	'<td><span data-price="'+price[i]+'" data-no="'+no[i]+'" data-id="'+id[i]+'" data-name="'+name[i]
	        	+'" data-unit="'+unit[i]
	        	+'" class="del_pan" onclick="del_goods(this)">删除</span></td>'+
	        	'</tr>';
	        	html+=tr;
			}else{
				layer.msg(name[i]+"商品已经添加请直接修改数量!");
				return;
			}
			
		}
		$("#goodslist{$type}",parent.document).append(html);
		var index = parent.layer.getFrameIndex(window.name); //获取窗口索引  
        parent.layer.close(index);  
		
//		var idstr=id_array.join(',');//将数组元素连接起来以构建一个字符串  
    });
</script>
<style>
.bank{
	width: 150px;
    height:30px;
    text-align:center;
    border-radius:5px;
}
</style>
{/block}